package com.system.user.controller;

import com.system.common.utils.R;
import com.system.user.entity.PayEntity;
import com.system.user.entityVO.PayVO;
import com.system.user.service.PayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Api(tags = "支付接口")
@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private PayService payService;

    /**
     * 查找所有支付信息，参数{"uid":1}
     *
     * @param map
     * @return
     */
    @ApiOperation("查找所有支付信息，参数{\"uid\":1}")
    @RequestMapping(value = "/queryAllByUid", method = RequestMethod.POST)
    public R queryAllByUid(@RequestBody Map<String, Object> map) {
        Integer uid = Integer.valueOf(map.get("uid").toString());
        List<PayEntity> pays = payService.queryByUid(uid);
        return R.ok().put("list", pays);
    }

    /**
     * 条件查询查找所有支付信息，电水表分类查询传入"bNumber":"w"参数（w表示水表，l表示水表），创建时间传入"createTime":"时间"
     *
     * @param pay
     * @return
     */
    @ApiOperation("条件查询查找所有支付信息，电水表分类查询传入\"bNumber\":\"w\"参数（w表示水表，l表示水表），创建时间传入\"createTime\":\"时间\"")
    @RequestMapping(value = "/queryAllByParam", method = RequestMethod.POST)
    public R queryAllByParam(@RequestBody PayVO pay) {
        List<PayVO> pays = payService.queryByParam(pay);
        return R.ok().put("list", pays);
    }

    /**
     * 支付操作，参数{"id":1}
     *
     * @param map
     * @return
     */
    @ApiOperation("支付操作，参数{\"id\":1}")
    @RequestMapping(value = "/updatePay", method = RequestMethod.POST)
    public R updatePay(@RequestBody Map<String, Object> map) {
        Integer id = Integer.valueOf(map.get("id").toString());
        boolean is_pay = payService.payment(id);
        if (is_pay) {
            return R.ok("支付成功！");
        }
        return R.error("支付失败！");
    }

}
